$(function () {
    var bannerSwiper = new Swiper('.swiper-container', {
        direction:'horizontal',
        loop: true,
        pagination: '.pagination',
        grabCursor: true,
        paginationClickable: true,
        autoplay: 5000,
        slideElement: 'li',
        lazyLoading: true,
        lazyLoadingInPrevNext: true
    });
    var checkSubmitFlg = false; 
    //提交
    $('.submit-info').click(function () {

        if(checkSubmitFlg ==true){ 
            return ; //当表单被提交过一次后checkSubmitFlg将变为true,根据判断将无法进行提交。 
        } 

        var username = $('input[name=username]').val(),
            phone = $('input[name=phone]').val(),
            addr = $('input[name=addr]').val();
            remark = $('input[name=remark]').val(),
            code = $('input[name=code]').val();

        var locationP = $('#location_p').val();
        var locationC = $('#location_c').val();
        var locationA = $('#location_a').val();

        if (!username) {
            alert('请输入收货人');
            return;
        }
        var telReg = /((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)/g;
        if (!telReg.test(phone)) {
            alert('请输入正确的手机或电话');
            return;
        }

        /*if (!locationP || !!locationC || !!locationA) {
            alert('请输入地址');
            return;
        }*/

        if (!addr) {
            alert('请输入详细地址');
            return;
        }

        //ajax

        $.ajax({
            url: ajaxUrl,
            type: 'post',
            data: {username:username,phone:phone,location_p:locationP,location_c:locationC,location_a:locationA,addr:addr,remark:remark,code:code},
            dataType: 'json',
            success: function (data) {
                if(data.status==200)
                {
                    checkSubmitFlg ==true;
                    window.location.href=redirectUrl;
                }else{
                    alert(data.msg);
                }
            }
        });

    });
    
});

var submitVal = $('.submit-val');
submitVal.keyup(function () {

    for (var i = 0; i<submitVal.length; i++ ) {
        if (!submitVal.eq(i).val()) {
            $('.submit-info').removeClass('black');
            return;
        }
    }
    $('.submit-info').addClass('black');
});